package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class PosSiteDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._


  def update(row: PosSiteRow) = {
    db.run(PosSite.insertOrUpdate(row)).map(_ => ())
  }

  def selectAll = db.run(PosSite.result)

  def insertOrUpdates(rows: Seq[PosSiteRow]) = {
    val action = {
      val delete = PosSite.delete
      val insertAll = PosSite ++= rows
      delete.flatMap(_ => insertAll)
    }.transactionally
    db.run(action).map(_ => ())
  }


}
